package com.hzit.util;

import cn.hutool.core.bean.BeanUtil;
import com.hzit.dto.StudentDTO;
import com.hzit.entity.Classes;
import com.hzit.entity.Student;
import com.hzit.mapper.ClassesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
public class Conver {
	@Autowired
	private ClassesMapper classesMapper;
	//1. 将传入的List<Student>转换为List<StudentDTO>
	public  List<StudentDTO> conver2DTO(List<Student> result) {
		return result.stream().map(m -> {
			StudentDTO dto = new StudentDTO();
			BeanUtil.copyProperties(m,dto,true);
			Classes classes = classesMapper.selectByPrimaryKey(m.getCid());
			dto.setCname(classes.getCname());
			return dto;
		}).collect(Collectors.toList());
	}
}
